#include "timer.h"

Timer::Timer (bool StartNow)
{
	if (StartNow)
	{
		StartTimer();
		Paused = false;
	}
	else
	{
		StartTime = 0;
		Paused = true;
	}

	PauseTime = 0;
	TimeSpentPaused = 0;
}

Timer::~Timer()
{
}

void Timer::StartTimer()
{
	StartTime = clock();
	PauseTime = 0;
	TimeSpentPaused = 0;
	Paused = false;
}

void Timer::PauseTimer()
{
	if (!Paused)
	{
		PauseTime = clock();
		Paused = true;
	}
}

void Timer::UnpauseTimer()
{
	if (Paused)
	{
		TimeSpentPaused += (clock() - PauseTime);
		Paused = false;
	}
}

clock_t Timer::GetCurrentTime()
{
	return clock();
}

clock_t Timer::GetStartTime()
{
	return StartTime;
}

clock_t Timer::GetAbsoluteTime()
{
	return (clock() - StartTime);
}

clock_t Timer::GetPauseTime()
{
	if (Paused)
	{
		return (TimeSpentPaused + (clock() - PauseTime));
	}
	else
	{
		return TimeSpentPaused;
	}
}

clock_t Timer::GetTime()
{
	return GetAbsoluteTime() - GetPauseTime();
}

bool Timer::IsPaused()
{
	return Paused;
}

